import store from '@/store'
// import defaultValue from './defaultValue'
let addjson = [
  {
    label: '站点',
    value: 'pcs',
    rule: [
      {
        required: true,
        message: `请输入站点`,
        trigger: 'blur',
      },
    ],
  },
  {
    label: '上级站点',
    value: 'pid',
    type: 'pcs',
    defaultValue: store.state.user.token.pcs,
  },
  {
    value: 'b_zf',
    label: '独立分润',
    type: 'select',
    option: [
      { value: '0', label: '不支付' },
      { value: '3', label: '支付' },
    ],
    defaultValue: '0',
  },

  {
    callbackasync: async (data) => {
      let r = []

      r.push({
        value: 'llfdef',
        label: '默认流量费',
        dw: '元',
        fl: 100,
        if: { zhi: [{ value: 'b_zf', zhi: [1, 2, 3] }] },
        defaultValue: 0,
      })
      let StatFr = await store.dispatch('statfr/getstatfrone', {
        pcs: store.state.user.token.pcs,
      })
      let llffridoptions = []
      if (data.llffrid == 0 || !data.llffrid) {
        llffridoptions.push({
          value: '0',
          label: '无',
        })
        // llffridoptions.push({
        //   value: '0',
        //   label: store.state.user.token.uUser,
        // })
      }
      StatFr.forEach(function (e) {
        llffridoptions.push({
          value: e['frid'],
          label: e['mc'] ? e['mc'] : '',
        })
      })
      let llffridstr = data.llffrid ? data.llffrid : 0
      let llffrid = llffridoptions.find(function (e) {
        return e.value == llffridstr
      })
      if (!llffrid) {
        llffrid = await store.dispatch('statfr/getstatfrone', {
          id: data.llffrid,
        })
        llffrid = llffrid.find((e) => {
          return e.frid == data.llffrid
        })
        if (llffrid) {
          llffridoptions.push({
            label: llffrid['mc'] ? llffrid['mc'] : '',
            value: llffrid['frid'],
          })
        }
      }
      r.push({
        value: 'llffrid',
        label: '流量费收款方',
        type: 'select',
        dw: '元',
        fl: 100,
        if: { zhi: [{ value: 'b_zf', zhi: [1, 2, 3] }] },
        option: llffridoptions,
        defaultValue: '0',
      })
      if (store.getters['upw/b_rz']) {
        let dffridoption = [],
          dffriddefaultValue = '0'
        dffridoption.push({ label: '平台', value: '0' })
        if (
          !(store.state.user.token.frid && store.state.user.token.frid != '0')
        ) {
          StatFr.forEach(function (e) {
            dffridoption.push({
              value: e.frid,
              label: e['mc'] ? e['mc'] : '',
            })
          })
        } else {
          // if ($scope.USearch.frid && $scope.USearch.frid != "0") {
          let USearchstatfr = await store.dispatch('statfr/getstatfrone', {
            id: store.state.user.token.frid,
          })
          USearchstatfr.forEach(function (e) {
            dffridoption.push({
              value: e.frid,
              label: e['mc'] ? e['mc'] : '',
            })
          })
          if ((data.dfdef == '0' || !data.dfdef) && USearchstatfr.length != 0) {
            dffriddefaultValue = USearchstatfr[0]['frid']
          }
        }
        // dffriddefaultValue
        let dffridstr = data.dffrid ? data.dffrid : dffriddefaultValue
        let dl = dffridoption.find(function (e) {
          return e.value == dffridstr
        })
        if (!dl) {
          dl = await store.dispatch('statfr/getstatfrone', {
            id: data.dffrid,
          })
          dl = dl.find((e) => {
            return e.frid == data.llffrid
          })
          if (dl) {
            dffridoption.push({
              label: dl['mc'] ? dl['mc'] : '',
              value: dl['frid'],
            })
          }
        }
        r.push(
          {
            label: '日租费',
            value: 'dfdef',
            dw: '元',
            fl: '100',
            if: { zhi: [{ value: 'b_zf', zhi: ['3'] }] },
            defaultValue: '0',
          },
          {
            value: 'dffrid',
            label: '日租费收款方',
            dw: '元',
            fl: 100,
            if: { zhi: [{ value: 'b_zf', zhi: [3] }] },
            option: dffridoption,
            type: 'select',
            defaultValue: dffriddefaultValue,
          }
        )
      }

      return r
    },
  },
  {
    label: '地址',
    value: 'mptxs',
    type: 'mpt',
    mptvalue: 'mpt',
    readonly: 'readonly',
    defaultValue: '',
  },
  { label: '管理员姓名', value: 'glxm' },
  { label: '管理员电话', value: 'gltel' },
  {
    label: '验证码',
    value: 'yzm',
    type: 'yzm',
    if: { zhi: [{ value: 'b_zf', zhi: [3] }] },
  },
]
let edtjson = [
  { label: '建站时间', value: 'sjc', type: 'button' },
  { label: '站点', value: 'pcs' },
  { label: '上级站点', value: 'pid', type: 'pcs' },
  { label: '地址', value: 'dz', type: 'mpt', mptvalue: 'mpt' },
  {
    callback(data) {
      if (data.b_dyfr == 1) {
        return []
      }
      if (!store.getters['upw/b_glf']) {
        return []
      }
      return [
        {
          value: 'b_dyfr',
          label: '管理费',
          type: 'select',
          option: [
            { value: '0', label: '没有' },
            { value: '2', label: '抽单模式' },
          ],
        },
        {
          value: 'b_dyfrm',
          label: '抽单比例',
          if: { zhi: [{ value: 'b_dyfr', zhi: ['2'] }] },
          defaultValue: '0',
        },
      ]
    },
  },
  {
    async callbackasync(data) {
      if (!data.id) {
        return
      }
      let r = [{ label: '独立分润', value: 'b_zf', type: 'select', option: [] }]
      if (store.getters['upw/b_rz']) {
        r.push({
          value: 'dfdef',
          label: '日租费',
          dw: '元',
          fl: '100',
          if: {
            zhi: [{ value: 'b_zf', zhi: ['3'] }],
          },
        })
        let dffridjson = {
          value: 'dffrid',
          label: '日租费收款方',
          type: 'select',
          option: dffridoptions,
          if: {
            zhi: [{ value: 'b_zf', zhi: ['3'] }],
          },
          defaultValue: '0',
        }
        let dffridoptions = [{ value: '0', label: '平台' }]
        if (
          !(store.state.user.token.frid && store.state.user.token.frid != '0')
        ) {
          let StatFruser = await store.dispatch('statfr/getstatfrone', {
            pcs: store.state.user.token.pcs,
          })
          StatFruser.forEach((e) => {
            dffridoptions.push({ value: e.frid, label: e.mc ? e.mc : '' })
          })
        } else {
          let StatFruser = await store.dispatch('statfr/getstatfrone', {
            id: store.state.user.token.frid,
          })
          if (StatFruser.length == 1) {
            let e = StatFruser[0]
            dffridoptions.push({ value: e.frid, label: e.mc ? e.mc : '' })
            dffridoptions.defaultValue = e.frid
          }
        }
        if (
          data.dffrid &&
          !dffridoptions.find((e) => {
            return e.value == data.dffrid
          })
        ) {
          let StatFruser = await store.dispatch('statfr/getstatfrone', {
            id: data.dffrid,
          })
          if (StatFruser.length == 1) {
            let e = StatFruser[0]
            dffridoptions.push({ value: e.frid, label: e.mc ? e.mc : '' })
          }
        }

        dffridjson.option = dffridoptions
        r.push(dffridjson)
        // $scope.select["dffrid"].push({"parameter": e["frid"], "explain": e["mc"] ? e["mc"] : ''});
        let StatFr = await store.dispatch('statfr/getstatfrone', {
          pcs: data.id,
        })
        StatFr.forEach((e) => {
          r.push({
            value: 'frid' + e.frid,
            label: e.mc,
            dw: '%',
            defaultValue: e.dfper,
            if: {
              zhi: [{ value: 'b_zf', zhi: ['3'] }],
            },
            lx: 'StatFredt',
            data: e,
            rule: [
              {
                required: true,
                message: `应该在0到100之间`,
                trigger: ['blur', 'change'],
                validator: (rule, value) => {
                  return value >= 0 && value <= 100
                },
              },
            ],
          })
        })
      }
      let option = [
        { value: '0', label: '不支付' },
        { value: '3', label: '支付' },
      ]
      if (['0', '3'].indexOf(String(data['b_zf'])) < 0) {
        option = [
          { value: '0', label: '不支付' },
          { value: '1', label: '每日支付' },
          { value: '2', label: '按月支付' },
          { value: '3', label: '提现支付' },
        ]
        let StationOldMsg = await store.dispatch('request/getRequest', {
          url: '/StationOldMsg',
          data: {
            id: data.id,
          },
        })
        StationOldMsg = StationOldMsg.length == 1 ? StationOldMsg[0] : {}
        r.push(
          {
            value: 'zfb',
            label: '流量费收款支付宝',
            readonly: 'readonly',
            if: {
              zhi: [{ value: 'b_zf', zhi: [1, 2] }],
            },
            defaultValue: StationOldMsg.zfb,
          },
          {
            value: 'zfbxm',
            label: '流量费收款姓名',
            readonly: 'readonly',
            if: {
              zhi: [{ value: 'b_zf', zhi: [1, 2] }],
            },
            defaultValue: StationOldMsg.zfbxm,
          }
        )
      }
      r[0].option = option
      return r
    },
  },

  {
    async callbackasync(data) {
      let r = [
        {
          value: 'llfdef',
          label: '默认流量费',
          dw: '元',
          fl: 100,
          if: { zhi: [{ value: 'b_zf', zhi: ['1', '2', '3'] }] },
        },
      ]
      let option = []
      if (data.llffrid == 0) {
        option.push({ value: '0', label: '无' })
        r[0].disabled = true
        r.push({
          value: 'llffrid',
          label: '流量费收款方',
          type: 'select',
          option: option,
          disabled: true,
          if: { zhi: [{ value: 'b_zf', zhi: ['3'] }] },
          defaultValue: '0',
        })
        return r
      }
      let StatFruser = await store.dispatch('statfr/getstatfrone', {
        pcs: store.state.user.token.pcs,
      })
      StatFruser.forEach((e) => {
        option.push({ value: e.frid, label: e.mc ? e.mc : '' })
      })
      if (
        !option.find((e) => {
          return e.value == data.llffrid
        })
      ) {
        let StatFruser = await store.dispatch('statfr/getstatfrone', {
          id: data.llffrid,
        })
        if (StatFruser.length == 1) {
          let e = StatFruser[0]
          option.push({ value: e.frid, label: e.mc ? e.mc : '' })
        }
      }
      r.push({
        value: 'llffrid',
        label: '流量费收款方',
        type: 'select',
        option: option,
        if: { zhi: [{ value: 'b_zf', zhi: ['3'] }] },
        defaultValue: '0',
      })
      return r
    },
  },
  { value: 'glxm', label: '管理员姓名' },
  { value: 'gltel', label: '管理员电话' },
  {
    label: '验证码',
    value: 'yzm',
    type: 'yzm',
    if: { zhi: [{ value: 'b_zf', zhi: [3] }] },
  },
]

export default { addjson, edtjson }
